<?php
/*
 *
* 通过路由设置改变URI参数
*
*/
CLASS ROUTER{
	var $uri;
	function __construct()
	{
		$this->uri =&load_class('URI', 'core');
	//	print_r($this->uri);
	}
	function _set_routing(){
		
		$this->uri->_get_uri();
	}
	function get_directory(){
	//	echo $this->uri->segments[1];
	//	if (is_dir(APPPATH.'controllers/'.$this->uri->segments[0]) && file_exists(APPPATH.'controllers/'.$this->uri->segments[0].'/'.$this->uri->segments[1].'.php') )
		if (isset($this->uri->segments[0]) && is_dir(APPPATH.'controllers/'.$this->uri->segments[0]) )
		{
			return $this->uri->segments[0];
		}else{
			return '';
		}	
	}
	function get_class(){
		if($this->get_directory()=='' && file_exists(APPPATH.'controllers/'.$this->uri->segments[0].'.php')){
			return 	$this->uri->segments[0];
		}elseif ( file_exists(APPPATH.'controllers/'.$this->uri->segments[0].'/'.$this->uri->segments[1].'.php') )
		{
			return 	$this->uri->segments[1];
		}else{
			if(!isset($this->uri->segments[1])){
				return 	"main";
			}else{
				exit('文件不存在,请检查路径是否正确！');
			}
			
			
		}
		
	}
	function get_method(){
			if( $this->get_directory()==$this->uri->segments[0]){
				return 	$this->uri->segments[1];
			}elseif( $this->get_directory()==$this->uri->segments[1]){
				return 	$this->uri->segments[2];
			}else{
				return "index";
			}
	}
}